int vy = 0;
    boolean onGround = false;

    void update() {
        if (leftHeld)  px -= speed;
        if (rightHeld) px += speed;

        vy += 1;          // gravity accelerates you down
        py += vy;         // apply velocity

        // temporary floor at the bottom of the window
        if (py + ph >= 480) {
            py = 480 - ph;
            vy = 0;
            onGround = true;
        }
    }

    public void keyPressed(KeyEvent e) {
        // ... existing arrow keys ...
        if (e.getKeyCode() == KeyEvent.VK_UP && onGround) {
            vy = -16;         // launch upward!
            onGround = false;
        }
    }